var personInfo=angular.module("user",[]);
personInfo.controller("userController",function($scope,$http,$rootScope){
    var req0={
        method:"GET",
        url:"clients/getComplain",
    };
    $http(req0)
        .then(function(res){
            if(res.data.msg=="SUCCESS"){
                $scope.orders=res.data.orders;
            }
        })
    $scope.sign = true;
    $scope.cu={};
    $scope.updateInfo=function(){
        if($scope.sign==true){
            $scope.sign = false;
        }
        else{
            if($scope.cu.ctel||$scope.cu.address){
                $scope.sign = true;
                var req={
                    method:"POST",
                    url:"clients/update",
                    data:$scope.cu,
                    headers:{"Content-type":"application/json"}
                };
                $http(req)
                    .then(function(res){
                        if(res.data.msg=="SUCCESS"){
                            $rootScope.user.ctel=$scope.cu.ctel;
                            $rootScope.user.address=$scope.cu.address;
                        }
                        else{
                            alert("FAILURE");
                        }
                    })
            }
        }
    };
    $scope.checkCTel=function(){
        if($scope.cu&&$scope.cu.ctel&&!/^(13[0-9]|15[0|1|3|6|7|8|9]|18[8|9])\d{8}$/.test($scope.cu.ctel)){
            $scope.cu.ctel="";
        }
    }
});